/*
@author: xyl
@file: 作业.go.go
@time: 2022/11/3 17:13
*/
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	//1.输出直角三角形
	var num1 int
	fmt.Print("请输入需要三角形行数:")
	fmt.Scan(&num1)
	i := 0
	b := "*"
	for i < num1 {
		i++
		fmt.Println(b)
		b += "**"
	}

	//2.输出九九乘法表
	for i := 1; i <= 9; i++ {
		for j := 1; j <= i; j++ {
			fmt.Printf("%d*%d=%d ", j, i, i*j)
		}
		fmt.Println()
	}

	//3.判断字母数字字符是否为回文,如果将大写字符转化为小写字符,并移除所有非字母数字字符后,
	//正向读和反向读都一样,那就是回文.无限次输入,按q退出
	//A,bc?: 1d,1C*ba  -- > abc1d1cba
	var str1, a string
	for {
		fmt.Println("请输入字符串: ")
		reader := bufio.NewReader(os.Stdin)
		str1, _ = reader.ReadString('\n')
		str2 := ""

		for i := 0; i < len(str1); i++ {
			if IsAlnum(str1[i]) {
				str2 = str2 + string(str1[i])
			}
		}

		str3 := strings.ToLower(str2)
		res := []rune(str3) //构造一个切片 类型是[]rune
		var len = len(res)
		var halfLen = len / 2
		var i int
		for i = 0; i < halfLen; i++ {
			if res[i] != res[len-i-1] {
				break
			}
		}

		if i == halfLen {
			fmt.Println("是回文")
		} else {
			fmt.Println("不是回文")
		}

		fmt.Println("请输入q退出，输入任意继续：")
		fmt.Scanln(&a)
		if a == "q" {
			break
		}
	}

}

func IsAlnum(b byte) bool {
	return (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || (b >= '0' && b <= '9')
}
